import BaseActions from '../../actions/index';

import TransferAction from '../../actions/transferModalAction';

class Actions extends BaseActions {
    constructor(comp) {
        super(comp);

        this.getTreeData = comp.getTreeData.bind(comp);
        this.getLanguage = comp.getLanguage.bind(comp);
        this.getTemplateData = comp.getTemplateData.bind(comp)
        this.getTableData = comp.getTableData.bind(comp);

        this.designAction = new TransferAction(comp);
    }

    // 人力资源组织改变
    orgChange = async (value) => {
        await this.comp.props.dispatch({
            type: 'gloRep/update',
            payload: {
                orgVal: value,
                treeEditable: true,
                pk_folder: ''
            }
        });
        this.comp.props.button.setButtonDisabled(['add', 'edit', 'paste', 'preview', 'delete', 'copy', 'design', 'auth', ''], false);
        this.getTreeData();
        this.comp.getTableData();
    }

    // 权限分配
    rightAssignment = () => {
        const {gloRep, dispatch, syncTree, openTo} = this.comp.props;
        const {language, selectedRow, orgVal} = gloRep;

        dispatch({
            type: 'gloRep/rightAssignment'
        })
            .then((res) => {
                if(res.success) {
                    openTo('/hrhi/hrreportassignment/organization/main/index.html', {
                        selectedRow: JSON.stringify(selectedRow),
                        orgValue: encodeURIComponent(JSON.stringify(orgVal)),
                        appcode: '600705A0'
                    })
                }
            });
    }
}

export default Actions;